﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace AvvaMobileNHibernateHelperKit.Objects
{
    public partial class PropertiesWindow : UserControl
    {
        public PropertiesWindow()
        {
            InitializeComponent();
        }

        #region Protected Fields

        protected int parentContainerWidth = 0;
        protected bool showProcess = true;
        protected bool hideOutput = false;
        int wait = 0;

        #endregion

        #region Public Properties

        /// <summary>
        /// 
        /// </summary>
        public int ParentContainerWidth
        {
            get
            {
                return parentContainerWidth;
            }
            set
            {
                parentContainerWidth = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public Object SelectedObject
        {
            get
            {
                return this.propertyGrid.SelectedObject;
            }
            set
            {
                //if(value != null)
                //{
                //    this.cmbObjects.SelectedText = value.ToString();
                //}
                this.propertyGrid.SelectedObject = value;
            }
        }

        #endregion

        #region Public Functions
        public override void Refresh()
        {
            this.propertyGrid.Refresh();
            base.Refresh();
        }

        public void ShowOutput(bool overrideComboBoxSelection)
        {
            timer.Enabled = true;
        }

        public void ShowOutput()
        {
            showProcess = true;
            this.ShowOutput(false);
        }

        public void HideOutput()
        {
            showProcess = false;
            this.ShowOutput(true);
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            if (showProcess == true)
            {
                if (this.Left >= parentContainerWidth - 300)
                {
                    this.Left -= 20;                    
                }
                else
                {
                    timer.Enabled = false;
                }
            }
            else
            {
                if (wait >= 50 && hideOutput == true)
                {
                    if (this.Left <= parentContainerWidth)
                    {                        
                        this.Left += 20;                        
                    }
                    else
                    {
                        //this.Width = 0;
                        timer.Enabled = false;
                        showProcess = true;
                        wait = 0;
                    }
                }
                else
                {
                    wait += 1;
                }
            }
        }

        
        private void Output_MouseLeave(object sender, EventArgs e)
        {
            hideOutput = true;
            
            if(hideOutput == true)
            {
                HideOutput();
            }
        }

        private void OutPutWindow_MouseEnter(object sender, EventArgs e)
        {
            wait = 0;
            hideOutput = false;
        }

        private void imgExitButton_Click(object sender, EventArgs e)
        {
            wait = 50;
            hideOutput = true;
            showProcess = false;
            timer.Enabled = true;
        }
        #endregion

        private void propertyGrid_MouseCaptureChanged(object sender, EventArgs e)
        {
        }

        private void PropertiesWindow_Load(object sender, EventArgs e)
        {
            //MainForm mf = (MainForm)this.FindForm();
            
            //foreach(Control ctrl in mf.Controls["pnlMain"].Controls)
            //{
            //    //this.cmbObjects.Items.Add(ctrl.Name);
            //}
        }










    }
}
